package array.leetcode.easy;

/**
 * @author bruin_du
 * @description 数组中出现次数超过一半的数字
 * @date 2022/6/5 20:17
 **/
public class Offer39_MajorityElement {
    public int majorityElement(int[] nums) {
        int x = nums[0];
        int tickets = 0;
        for (int num : nums) {
            if(tickets == 0){
                x = num;
            }
            if(num == x){
                tickets++;
            }else{
                tickets--;
            }
        }
        return x;
    }
}
